package main

import (
	"context"
	"fmt"
	"log"
	"net"
	"strconv"
	pb "testpb"

	"google.golang.org/grpc"
)

type server struct {
}

func (server *server) GetHello(ctx context.Context, in *pb.HelloRequest) (ret *pb.HelloResponse, err error) {
	fmt.Println("ctx userKey", ctx.Value("user-agent"))
	ret = &pb.HelloResponse{
		Code:   200,
		RetMsg: "hello baby" + strconv.Itoa(int(in.Id)),
	}
	return
}

func main() {

	l, err := net.Listen("tcp", ":8080")
	if err != nil {
		panic(err)
	}
	s := grpc.NewServer()
	pb.RegisterHelloServiceServer(s, new(server))
	if err := s.Serve(l); err != nil {
		log.Fatalf("failed to serve: %v", err)
	}
}
